//
//  UserHelper.m
//  Router
//
//  Created by gejiangs on 15/10/16.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "UserHelper.h"
#import "LoginResponseModel.h"

@implementation UserHelper
- (void)registerWithPhone:(NSString *)phone
                 password:(NSString *)password
                  success:(RequestSussess)success
                  failure:(RequestFailure)failure
{
    NSAssert(phone!= nil, @"手机号不能为空");
    NSAssert(password != nil, @"密码不能为空");
    NSDictionary *param = @{@"user":phone,
                            @"pwd":password,
                            };
    
    [self.requestOperator requestPostWithURL:User_Register_POST_URL params:param success:^(BOOL succ, id responseObject) {
        NSString *info = responseObject[@"info"];
        if ([info isEqualToString:@"userInsert"])
        {
            success(YES,responseObject,NSLocalizedString(info, @""));
        }
        else
        {
            success(NO,responseObject,NSLocalizedString(info, @""));
        }
    } failure:failure];

}




- (void)loginWithPhone:(NSString *)phone password:(NSString *)password success:(RequestSussess)success failure:(RequestFailure)failure
{
    NSAssert(phone!= nil, @"手机号不能为空");
    NSAssert(password != nil, @"密码不能为空");
    NSDictionary *param = @{@"user":phone,
                            @"pwd":password};
    [self.requestOperator requestPostWithURL:User_Login_POST_URL params:param success:^(BOOL succ, id responseObject) {
        LoginResponseModel *model = [LoginResponseModel objectWithKeyValues:responseObject error:nil];
        if ([model.info isEqualToString:@"LoginSuccess"]) {
            success(YES,model,NSLocalizedString(model.info, @""));
        }
        else{
            success(NO,model,NSLocalizedString(model.info, @""));
        }
    } failure:failure];
}

- (void)sendSMSWithPhone:(NSString *)phone
                 success:(RequestSussess)success
                 failure:(RequestFailure)failure
{
    NSDictionary *param = @{@"phone":phone};
    [self.requestOperator requestPostWithURL:User_SendSMS_POST_URL params:param success:^(BOOL succ, id responseObject) {
        /// 成功返回一个这样的鬼东西
//        {"code":"000/Send:1/Consumption:.07/Tmoney:662.13/sid:1021160752654435","r":"737669"}
        success(YES,responseObject,nil);
    } failure:failure];
}



- (void)findBackPasswordWithPhone:(NSString *)phone password:(NSString *)password deviceID:(NSString *)deviceID success:(RequestSussess)success failure:(RequestFailure)failure
{
    NSDictionary *param = @{@"user":phone,
                            @"pwd":password,
                            @"deviceID":deviceID};
    
    [self.requestOperator requestPostWithURL:User_Modify_PSOT_URL params:param success:^(BOOL succ, id responseObject) {
        NSString *info = responseObject[@"info"];
        if ([info isEqualToString:@"pwdUpdate"])
        {
            success(YES,responseObject,NSLocalizedString(info, @""));
        }
        else{
            success(NO,responseObject,NSLocalizedString(info, @""));
        }
    } failure:failure];
}



- (void)setNickNameWithUser:(NSString *)user userNickName:(NSString *)nickName success:(RequestSussess)success failure:(RequestFailure)failure
{
    
    NSDictionary *param = @{@"user":user,
                            @"userNickName":nickName};
    [self.requestOperator requestPostWithURL:User_Setting_NickName_POST_URL params:param success:^(BOOL succ, id responseObject) {
        success(YES,responseObject,nil);
    } failure:failure];
}

@end
